package com.api.shopapi.mapper;

import com.api.shopapi.entity.GoodsSize;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface GoodsSizeMapper {

    @Insert("insert into  goods_size " +
            "(" +
            "GoodsSizeCode, " +
            "Name, " +
            "Status" +
            ") " +
            "VALUES " +
            "(" +
            "#{goodsSize.GoodsSizeCode} ," +
            "#{goodsSize.Name} ," +
            "#{goodsSize.Status} " +
            ")")
    int insert(@Param("goodsSize") GoodsSize goodsSize);

    @Update("update goods_size set " +
            "Name=#{goodsSize.Name} ," +
            "Status=#{goodsSize.Status}  " +
            "where " +
            "GoodsSizeCode=#{goodsSize.GoodsSizeCode}  ")
    int update(@Param("goodsSize") GoodsSize goodsSize);


    @Select("select * from goods_size where Name=#{name} limit 1")
    GoodsSize getByName(@Param("name") String name);

    @Select("select * from  goods_size where GoodsSizeCode=#{goodsSizeCode} limit 1")
    GoodsSize getByGoodsSizeCode(@Param("goodsSizeCode") String goodsSizeCode);


    @Select("<script>" +
            "select  * from goods_size where 1=1  " +
            " <if test =' status !=-1 '>" +
            "  and Status=#{status}  " +
            " </if>" +
            " <if test ='name !=null and name!=\"\"  '>" +
            "  and Name like concat('%',#{name},'%')  " +
            " </if>" +
            "</script> ")
    List<GoodsSize> getList(@Param("status") int status,
                            @Param("name") String name);

    @Select("select * from goods_size where Status=1")
    List<GoodsSize> getAllList();

}
